package com.wlts.wzy.util;

import com.alibaba.fastjson.JSON;
import com.wlts.wzy.DYUserModule.entity.DyStoreUser;
import com.wlts.wzy.KSUserModule.entity.KsStoreUser;
import com.wlts.wzy.sys_shiro.entity.SysUser;
import org.apache.shiro.subject.Subject;


public class LoginUserUtil {
    /**
     * 获得登录系统用户
     *
     * @param subject
     * @return
     */
    public static SysUser getLoginSysUser(Subject subject) {
        Object obj = subject.getPrincipals().getPrimaryPrincipal();
        SysUser sysUserModel;
        if (obj instanceof SysUser) {
            sysUserModel = (SysUser) obj;
        } else {
            sysUserModel = JSON.parseObject(JSON.toJSON(obj).toString(), SysUser.class);
        }
        return sysUserModel;
    }

    /**
     * 获得登录商户
     *
     * @param subject
     * @return
     */
    public static KsStoreUser getLoginKsStoreUser(Subject subject) {
        Object obj = subject.getPrincipals().getPrimaryPrincipal();
        KsStoreUser sysUserModel;
        if (obj instanceof KsStoreUser) {
            sysUserModel = (KsStoreUser) obj;
        } else {
            sysUserModel = JSON.parseObject(JSON.toJSON(obj).toString(), KsStoreUser.class);
        }
        return sysUserModel;
    }
    /**
     * 获得抖音商户信息
     *
     * @param subject
     * @return
     */
    public static DyStoreUser getLoginDyStoreUser(Subject subject) {
        Object obj = subject.getPrincipals().getPrimaryPrincipal();
        DyStoreUser sysUserModel;
        if (obj instanceof DyStoreUser) {
            sysUserModel = (DyStoreUser) obj;
        } else {
            sysUserModel = JSON.parseObject(JSON.toJSON(obj).toString(), DyStoreUser.class);
        }
        return sysUserModel;
    }


}
